package com.gosophia.dataDictionary.test.unit;

import java.util.List;

import junit.framework.Assert;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import com.gosophia.dataDictionary.dao.DataValueDAO;
import com.gosophia.dataDictionary.entity.DataValue;

/**
 * DataValueDAOImpl类的测试类
 * 
 * @author nana
 * 
 */
@ContextConfiguration(locations = { "classpath*:moduleContext.xml",
        "classpath:applicationContext-dao-ut.xml" })
@Transactional
@TransactionConfiguration(defaultRollback = true)
public class UTDataValueDAO extends
        AbstractTransactionalJUnit4SpringContextTests {

    @Autowired
    DataValueDAO dataValueDAO;


    @Test
    public void testGetDataValueByEntryIdAndKey() {
        DataValue dataValue = dataValueDAO.getDataValueByEntryIdAndKey(1016L,"001");
        Assert.assertEquals("男", dataValue.getValue());
    }

    @Test
    public void testGetEnabledDataValueByEntryIdByPage() {
        List<DataValue> list = dataValueDAO.getEnabledDataValueByEntryId(1025L);
        Assert.assertEquals(9, list.size());

    }

    @Test
    public void testFindSameValueOrKeyByEntryId() {
        List<DataValue> list = dataValueDAO.getSameValueOrKeyByEntryId("男",
                "", 1016L);
        Assert.assertEquals(1, list.size());
        List<DataValue> list2 = dataValueDAO.getSameValueOrKeyByEntryId("",
                "001", 1016L);
        Assert.assertEquals(1, list2.size());
    }

    @Test
    public void testFindSameValueOrKeyByEntryIdExceptByDataValueId() {
        List<DataValue> list = dataValueDAO
                .getSameValueOrKeyByEntryIdExceptByDataValueId("男", "", 1016L,
                        1031L);
        Assert.assertEquals(0, list.size());
        List<DataValue> list2 = dataValueDAO
                .getSameValueOrKeyByEntryIdExceptByDataValueId("", "001",
                        1016L, 1031L);
        Assert.assertEquals(0, list2.size());
        List<DataValue> list3 = dataValueDAO
                .getSameValueOrKeyByEntryIdExceptByDataValueId("男", "", 1016L,
                        2L);
        Assert.assertEquals(1, list3.size());

    }

    @Test
    public void testDeleteDataValueByIdAndVersion() {
        dataValueDAO.deleteDataValueByIdAndVersion(1008L, 0L);
        DataValue dataValue = dataValueDAO.get(1008L);
        Assert.assertEquals(null, dataValue);
    }
    
    @Test
    public void testGetDataValueByEntryNameAndKey(){
        DataValue dataValue = dataValueDAO.getDataValueByEntryNameAndKey("sex", "001");
        Assert.assertNotNull(dataValue);
    }
    
    @Test
    public void testGetEnabledDataValueByEntryName(){
        List<DataValue> dataValues = dataValueDAO.getEnabledDataValueByEntryName("sex");
        Assert.assertEquals(1, dataValues.size());
    }
    
    @Test
    public void testGetDataValueByIndexNotLessThanToId(){
        List<DataValue> dataValues = dataValueDAO.getDataValueByIndexNotLessThanToId(10, 1025L);
        Assert.assertEquals(3, dataValues.size());
    }
    
    @Test
    public void testGetDataValueBetweenIdMoveUp(){
        List<DataValue> dataValues = dataValueDAO.getDataValueBetweenIdMoveUp(2, 6, 1025L);
        Assert.assertEquals(3, dataValues.size());
    }
    
    @Test
    public void testGetDataValueBetweenIdMoveDown(){
        List<DataValue> dataValues = dataValueDAO.getDataValueBetweenIdMoveDown(6, 2, 1025L);
        Assert.assertEquals(4, dataValues.size());
    }

}
// /:~
